/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conn;

import dao.PersonDao;
import exec.NotFoundException;
import java.sql.Date;
import java.sql.SQLException;
import java.util.List;
import obj.Person;

/**
 *
 * @author jm1156
 */
public class EMIS4Connection extends DatabaseConnection {

    private static EMIS4Connection instance;

    private EMIS4Connection() {
        super("mysql",
                "66.197.136.195",
                "3306",
                "emisredb_trusted",
                "emisredb_emis4",
                "trusted");
    }

    public static EMIS4Connection getInstance() {
        if(instance == null)
            instance = new EMIS4Connection();
        return instance;
    }
    

    public static void main(String[] args) {
        EMIS4Connection EMIS4Connection = new EMIS4Connection();
        System.out.println("Able to connect: " + EMIS4Connection.connect());
        System.out.println("Connection: " + EMIS4Connection.getConnection());

        Person person = new Person();
        person.setDOB(new Date(System.currentTimeMillis()));
        person.setEmail("haha@haha.com");
        person.setFirstName("Jason");
        person.setLastName("Bell");
        person.setSexID(0);
        person.setSSN(123456789);

        PersonDao personDao = new PersonDao();
        try {
            personDao.create(EMIS4Connection.getConnection(), person);
            
            List people = personDao.searchMatching(EMIS4Connection.getConnection(), person);
            person = (Person)people.get(0);
            System.out.println("Person: " + person);
            personDao.delete(EMIS4Connection.getConnection(), person);
        } catch (SQLException ex) {
            ex.printStackTrace();
        } catch (NotFoundException ex) {
            ex.printStackTrace();
        }
    }
}
